home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / database / blt2rx_o.zip / SCRIPTS.ZIP / 08CP.CMD < prev   
OS/2 REXX Batch file  |  1996-08-05  |  11KB  |  304 lines

  1. /* 08 - CP/DosXXX example for Bullet/REXX */
  2. /* 3-Aug-96
  3.    Calls made in this example:
  4.    - blt_Init()
  5.    - blt_MkDirDos() [optional]
  6.    - blt_CreateFileDos()
  7.    - blt_AccessFileDos()
  8.    - blt_OpenFileDos()
  9.    - blt_ExpandFileDos()
  10.    - blt_SeekFileDos()
  11.    - blt_WriteFileDos()
  12.    - blt_ReadFileDos()
  13.    - blt_CommitFileDos()
  14.    - blt_CloseFileDos()
  15.    - blt_RenameFileDos()
  16.    - blt_DeleteFileDos()
  17.    - blt_Exit()
  18. */
  19.  
  20. /* Typically, each test routine's arg pack (blt_IP., etc.) is set to NOVALUE */
  21. /* so that any unset variables can easily be identified.  In actual use, */
  22. /* this would not be necessary since often arg pack values are already setup */
  23. /* for multiple calls, where blt_?P.variable is already properly set up */
  24.  
  25.  say "Example: 08cp.cmd  (recommend output be redirected to a file)"
  26.  
  27.  call RxFuncAdd 'BulletLoadFuncs', 'BREXXI2', 'BulletLoadFuncs'
  28.  call BulletLoadFuncs
  29.  
  30.  testFilename = "08CP.RAW"
  31.  testNewname  = "08CP.REN"
  32.  testWriteData = "<08 test data3456 (rest of data in this file is uninitialized disk space)>"
  33.  
  34.  fileID = 0
  35.  
  36.  /* in case Bullet/REXX is still active, close it out */
  37.  
  38.  rez = blt_Exit()
  39.  
  40.  say
  41.  say "calling blt_Init()"
  42.  blt_IP.=NOVALUE
  43.  blt_IP.JFTsize=5       /* must be 5 */
  44.  rez = blt_Init()       /* init Bullet/REXX */
  45.  say " blt_IP.func is" blt_IP.func
  46.  say " blt_IP.stat is" blt_IP.stat  /* rez same as stat except for xactions */
  47.  if rez = 0 then do
  48.  
  49.     say " blt_IP.versionDOS is" blt_IP.versionDOS
  50.     say " blt_IP.versionOS is" blt_IP.versionOS
  51.     say " blt_IP.versionBullet is" blt_IP.versionBullet
  52.     /* say " blt_IP.exitPtr is" blt_IP.exitPtr */
  53.  
  54.     /* delete lingering file by both original and new names */
  55.  
  56.     blt_DFP.=NOVALUE
  57.     blt_DFP.filename = testFilename
  58.     rez = blt_DeleteFileDos();
  59.     blt_DFP.filename = testNewname
  60.     rez = blt_DeleteFileDos();
  61.     rez = 0  /* ignore any error */
  62.  
  63.     /* since there's no blt_RmDir() this defaults to not-done */
  64.     /*
  65.     say
  66.     say "calling blt_MkDirDos()"
  67.     blt_DFP.=NOVALUE
  68.     blt_DFP.filename = ".\08DIR"
  69.     rez = blt_MkDir()
  70.     say " blt_DFP.func is" blt_DFP.func
  71.     say " blt_DFP.stat is" blt_DFP.stat
  72.     if rez = 0 then rez = 0
  73.     */
  74.  
  75.     if rez = 0 then do
  76.        say
  77.        say "calling blt_CreateFileDos()"
  78.        blt_DFP.=NOVALUE
  79.        blt_DFP.filename = testFilename
  80.        blt_DFP.attr = 0
  81.        rez = blt_CreateFileDos()
  82.        say " blt_DFP.func is" blt_DFP.func
  83.        say " blt_DFP.stat is" blt_DFP.stat
  84.        if rez = 0 then do
  85.  
  86.           say
  87.           say "calling blt_AccessFileDos()  [asMode=18, or 0x12=R/W access & DENY-R/W share]"
  88.           blt_DFP.=NOVALUE
  89.           blt_DFP.filename = testFilename
  90.           blt_DFP.asMode = 18
  91.           rez = blt_AccessFileDos()
  92.           say " blt_DFP.func is" blt_DFP.func
  93.           say " blt_DFP.stat is" blt_DFP.stat
  94.           if rez = 0 then do
  95.  
  96.              say
  97.              say "calling blt_OpenFileDos()"
  98.              blt_DFP.=NOVALUE
  99.              blt_DFP.filename = testFilename
  100.              blt_DFP.asMode = 18
  101.              rez = blt_OpenFileDos()
  102.              say " blt_DFP.func is" blt_DFP.func
  103.              say " blt_DFP.stat is" blt_DFP.stat
  104.              if rez = 0 then do
  105.  
  106.                 fileID = blt_DFP.handle
  107.                 say " blt_DFP.handle is" fileID
  108.                 say
  109.                 say "calling blt_ExpandFileDos()  [expanding empty file to 888 bytes]"
  110.                 blt_DFP.=NOVALUE
  111.                 blt_DFP.handle = fileID
  112.                 blt_DFP.bytes = 888
  113.                 rez = blt_ExpandFileDos()
  114.                 say " blt_DFP.func is" blt_DFP.func
  115.                 say " blt_DFP.stat is" blt_DFP.stat
  116.                 if rez = 0 then do
  117.  
  118.                    say
  119.                    say "calling blt_SeekFileDos() [getting filesize]"
  120.                    blt_DFP.=NOVALUE
  121.                    blt_DFP.handle = fileID
  122.                    blt_DFP.seekTo = 0
  123.                    blt_DFP.method = 2
  124.                    rez = blt_SeekFileDos()
  125.                    say " blt_DFP.func is" blt_DFP.func
  126.                    say " blt_DFP.stat is" blt_DFP.stat
  127.                    filesize = blt_DFP.seekTo
  128.  
  129.                    /* restore file pointer to start of file (without any fuss) */
  130.  
  131.                    if rez = 0 then do
  132.                       blt_DFP.seekTo = 0
  133.                       blt_DFP.method = 0
  134.                       rez = blt_SeekFileDos()
  135.                       if rez then say "Re-seek after filesize failed:" rez
  136.                    end
  137.                    if rez = 0 then do
  138.  
  139.                       say " blt_DFP.SeekTo (filesize) is" filesize
  140.                       say
  141.                       say "calling blt_WriteFileDos()"
  142.                       blt_DFP.=NOVALUE
  143.                       blt_DFP.handle = fileID
  144.                       blt_DFP.bytes = length(testWriteData)
  145.                       blt_DFP.bufferData = testWriteData
  146.                       rez = blt_WriteFileDos()
  147.                       say " blt_DFP.func is" blt_DFP.func
  148.                       say " blt_DFP.stat is" blt_DFP.stat
  149.                       if rez = 0 then do
  150.  
  151.                          bytesWritten = blt_DFP.bytes
  152.                          blt_DFP.seekTo = 0
  153.                          blt_DFP.method = 0
  154.                          rez = blt_SeekFileDos()
  155.                          if rez then say "Re-seek after write failed:" rez
  156.                          if rez = 0 then do
  157.  
  158.                             say
  159.                             say "calling blt_ReadFileDos()  [read" bytesWritten "bytes written]"
  160.                             blt_DFP.=NOVALUE
  161.                             blt_DFP.handle = fileID
  162.                             blt_DFP.bytes = bytesWritten
  163.                             rez = blt_ReadFileDos()
  164.                             say " blt_DFP.func is" blt_DFP.func
  165.                             say " blt_DFP.stat is" blt_DFP.stat
  166.                             if rez = 0 then do
  167.  
  168.                                say " blt_ReadFileDos() buffer is '"blt_DFP.bufferData"'"
  169.                                say
  170.                                say "calling blt_CommitFileDos()"
  171.                                blt_DFP.=NOVALUE
  172.                                blt_DFP.handle = fileID
  173.                                rez = blt_CommitFileDos()
  174.                                say " blt_DFP.func is" blt_DFP.func
  175.                                say " blt_DFP.stat is" blt_DFP.stat
  176.                                if rez = 0 then do
  177.  
  178.                                   say
  179.                                   say "calling blt_CloseFileDos()"
  180.                                   blt_DFP.=NOVALUE
  181.                                   blt_DFP.handle = fileID
  182.                                   rez = blt_CloseFileDos()
  183.                                   say " blt_DFP.func is" blt_DFP.func
  184.                                   say " blt_DFP.stat is" blt_DFP.stat
  185.                                   if rez = 0 then do
  186.  
  187.                                      fileID = 0  /* handle no longer exists */
  188.                                      say
  189.                                      say "calling blt_RenameFileDos()"
  190.                                      blt_DFP.=NOVALUE
  191.                                      blt_DFP.filename = testFilename
  192.                                      blt_DFP.newName = testNewname
  193.                                      rez = blt_RenameFileDos()
  194.                                      say " blt_DFP.func is" blt_DFP.func
  195.                                      say " blt_DFP.stat is" blt_DFP.stat
  196.                                      if rez = 0 then do
  197.  
  198.                                         say
  199.                                         say "calling blt_DeleteFileDos()"
  200.                                         blt_DFP.=NOVALUE
  201.                                         blt_DFP.filename = testNewname
  202.                                         rez = blt_DeleteFileDos()
  203.                                         say " blt_DFP.func is" blt_DFP.func
  204.                                         say " blt_DFP.stat is" blt_DFP.stat
  205.                                         if rez = 0 then do
  206.  
  207.                                            say
  208.                                            say "Excellent!  All calls went as planned"
  209.                                         end
  210.                                         else do
  211.                                            say "* ERROR * blt_DeleteFileDos()"
  212.                                         end
  213.  
  214.                                      end
  215.                                      else do
  216.                                         say "* ERROR * blt_RenameFileDos()"
  217.                                      end
  218.  
  219.                                   end
  220.                                   else do
  221.                                      say "* ERROR * blt_CloseFileDos()"
  222.                                   end
  223.  
  224.                                end
  225.                                else do
  226.                                   say "* ERROR * blt_CommitFileDos()"
  227.                                end
  228.  
  229.                             end
  230.                             else do
  231.                                say "* ERROR * blt_ReadFileDos()"
  232.                             end
  233.  
  234.                          end
  235.                          else do
  236.                             say "* ERROR * blt_SeekFileDos()"
  237.                          end
  238.  
  239.                       end
  240.                       else do
  241.                          say "* ERROR * blt_WriteFileDos()"
  242.                       end
  243.  
  244.                    end
  245.                    else do
  246.                       say "* ERROR * blt_SeekFileDos()"
  247.                    end
  248.  
  249.                 end
  250.                 else do
  251.                    say "* ERROR * blt_ExpandFileDos()"
  252.                 end
  253.  
  254.                 if fileID <> 0 then do
  255.                    blt_DFP.handle = fileID
  256.                    rez = blt_CloseFileDos()
  257.                 end
  258.  
  259.              end
  260.              else do
  261.                 say "* ERROR * blt_OpenFileDos()"
  262.              end
  263.  
  264.           end
  265.           else do
  266.              say "* ERROR * blt_AccessFileDos"
  267.           end
  268.  
  269.           /* get rid of lingering file or leave them to */
  270.           /* as done here so you can check it out on error */
  271.           /*
  272.           blt_DFP.filename = testFilename
  273.           rez = blt_DeleteFileDos();
  274.           blt_DFP.filename = testNewname
  275.           rez = blt_DeleteFileDos();
  276.           */
  277.  
  278.        end
  279.        else do
  280.           say "* ERROR * blt_CreateFileDos()"
  281.        end
  282.  
  283.     end
  284.     else do
  285.        say
  286.        say "* ERROR * blt_MkDir()  (optionally called)"
  287.     end
  288.  
  289.     say
  290.     say "calling blt_Exit()"
  291.     blt_EP.=NOVALUE
  292.     rez = blt_Exit()
  293.     say " blt_EP.func is" blt_EP.func
  294.     say " blt_EP.stat is" blt_EP.stat
  295.     say " blt_EP.rxAllocsLeft is" blt_EP.rxAllocsLeft
  296.  end
  297.  else do
  298.     say
  299.     say "* ERROR * blt_Init()"
  300.  end
  301.  
  302.  call BulletDropFuncs
  303.  exit 0
  304.